"""
@title(TenX腾晓2024年12月考核答题文件)
@warning(请勿修改参数和返回值)
@warning(请认真填写__init__中的数据)
@author(1323230180)
@license(CC BY-SA 4.0 License)
"""
import os
from copy import deepcopy


class TenXClass:
    def __init__(self):
        # 获取当前文件名并截取文件名的学号-姓名
        file_name = os.path.basename(__file__).split('.')[0].split("-")
        self.id = file_name[0]  # 学号
        self.name = file_name[1]  # 姓名

    @staticmethod
    def question1(*args) -> list[str]:
        binary_tree = deepcopy(args[0])  # 传入的地牢结构（二叉树），详细请看BinaryTree.py
        result = []
        def dfs(node, path):
            if node is None:
                return
            new_path = path + str(node.value)
            if node.value == 0 and node.left is None and node.right is None:
                result.append(new_path)
            dfs(node.left, new_path)
            dfs(node.right, new_path)
        if binary_tree.root:
            dfs(binary_tree.root, "")
        return result

    @staticmethod
    def question2(*args) -> str:
        matrix = deepcopy(args[0])  # 传入的河流结构（矩阵）
        max_nums = [str(max(row)) for row in matrix]
        return ''.join(max_nums)

    @staticmethod
    def question3(*args) -> int:
        MOD = 99999999
        def power_mod(base, exp):
            result = 1
            base %= MOD
            while exp > 0:
                if exp % 2 == 1:
                    result = (result * base) % MOD
                exp //= 2
                base = (base * base) % MOD
            return result
        total_without_restrictions = (7 * power_mod(7, 999)) % MOD
        total_without_nine = (7 * power_mod(6, 999)) % MOD
        return (total_without_restrictions - total_without_nine) % MOD

    @staticmethod
    def question4(*args) -> int:
        n = deepcopy(args[0])  # 用于搭建金字塔的球个数
        total_beads = 0
        layers = 0
        while total_beads <= n:
            layers += 1
            total_beads += layers * (layers + 1) // 2
        return layers - 1

    @staticmethod
    def question5(*args) -> str:
        balls = deepcopy(args[0])  # 五行空间球的初始值
        new_balls = balls.copy()
        max_iterations = 1000  # 最大迭代次数
        iteration_count = 0
        while iteration_count < max_iterations:
            for i in range(len(balls)):
                if i == 0:
                    new_balls[0] = balls[3] + balls[4]
                elif i == 1:
                    new_balls[1] = balls[4] + new_balls[0]
                elif i == 2:
                    new_balls[2] = new_balls[0] + new_balls[1]
                elif i == 3:
                    new_balls[3] = new_balls[1] + new_balls[2]
                elif i == 4:
                    new_balls[4] = new_balls[2] + new_balls[3]
                if all(b >= 10000 for b in new_balls):
                    return str(new_balls)
                balls = new_balls.copy()
                new_balls = balls.copy()
            iteration_count += 1
        return str(new_balls)